package cn.com.open.itembank.logic.questiontype;

import cn.com.open.itembank.dto.QuestionImportModel;
import cn.com.open.itembank.dto.QuestionModel;

/**
 * Created by lucky on 2017/12/19.
 */
public class TextEntryItem extends QuestionTypeBase {
    /**
     * Instantiates a new Text entry item.
     *
     * @param model the model
     */
    public TextEntryItem(QuestionImportModel model) {
        super(model);
    }

    //region 校验填空数与答案数是否匹配

    /**
     * 校验填空数与答案数是否匹配.
     *
     * @return the boolean
     */
    @Override
    protected boolean checkAnswerCount() {
        boolean result = true;
        int mainContent = importModel.getPrompt().split("##", -1).length - 1;

        if (mainContent > importModel.getAnswer().size()) {
            result = false;
            importModel.setErrorInfo("填空数大于答案数；");
        } else {
            if (mainContent < importModel.getAnswer().size()) {
                result = false;
                importModel.setErrorInfo("填空数小于答案数；");
            }
        }

        return result;
    }
    //endregion

    //region 校验答案界限

    /**
     * 校验答案界限.
     *
     * @return the boolean
     */
    @Override
    protected boolean checkAnswerLimit() {
        return true;
    }
    //endregion

    //region 获取保存模型

    /**
     * 获取保存模型.
     *
     * @return the input question model
     */
    @Override
    public QuestionModel getSaveModel() {
        QuestionModel model = super.getSaveModel();
        //I6,I7 需要各种题型重载完成
        for (String answer : importModel.getAnswer()) {
            model.getI6().add(answer);
            model.getI7().add("1");
        }
        //I17 子试题个数 需要各种题型重载完成
        model.setI17(importModel.getAnswer().size());
        //importModel的objective的 是 表示是客观题,i32的客观题0，主观题1
        model.setI32("是".equalsIgnoreCase(importModel.getIsObjective()) ? 0 : 1);

        return model;
    }
    //endregion
}
